package com.example.admin.controller;

import com.example.admin.common.result.R;
import com.example.admin.common.util.CaptchaUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Api(tags = "验证码接口")
@RestController
@RequestMapping("/api/captcha")
@CrossOrigin
public class CaptchaController {

    @ApiOperation("获取验证码")
    @GetMapping("/get")
    public R<Map<String, String>> getCaptcha(HttpSession session) {
        String captcha = CaptchaUtil.generateCaptcha();
        // 将验证码存入session
        session.setAttribute("captcha", captcha.toLowerCase());
        
        Map<String, String> data = new HashMap<>();
        data.put("captcha", captcha);
        return R.ok(data);
    }
} 